package com.zretc.service.impl;

/**
 * 袁大力
 */

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zretc.dao.CommentMapper;
import com.zretc.entity.Comment;
import com.zretc.service.CommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
@Service
public class CommentServiceImpl implements CommentService {

    @Autowired
    private CommentMapper commentMapper;
    @Override
    public int addCommentMessage(Map<String,String> commentMap) {
        return commentMapper.insertCommentMessage(commentMap);
    }

    @Override
    public List<Map<String, Object>> getFirstCommentMessage(String movieId) {
        return commentMapper.findFirstCommentMessage(movieId);
    }

    @Override
    public List<Map<String, Object>> getMoreCommentMessage(Map<String, String> params) {
        return commentMapper.findMoreCommentMessage(params);
    }

    @Override
    public List<Comment> getCommentByAccountId() {
        return commentMapper.findCommentByAccountId();
    }

    @Override
    public PageInfo<Map<String,Object>> getComment(Map<String, String> params) {
        int pageNum = Integer.parseInt(params.get("pageNum"));
        int pageSize = Integer.parseInt(params.get("pageSize"));
        String accountName = params.get("accountName");
        PageHelper.startPage(pageNum, pageSize);

        if (accountName == null || "".equals(accountName)) {
            params.put("accountName", null);
        } else {
            params.put("accountName", accountName);
        }
        List<Map<String,Object>> list = commentMapper.findComment(params);

        PageInfo<Map<String,Object>> pageInfo = new PageInfo<>(list);
        return pageInfo;
    }

    @Override
    public boolean delCommentBycommentId(String commentId) {
        return commentMapper.delCommentBycommentId(commentId);
    }
}
